#!/usr/bin/env bash
echo "请先确保网络连接正常"
# for ubuntu22
sudo sh -c 'cat <<EOF >/etc/apt/sources.list
   # 阿里云源
   deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
   deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

   deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
   deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

   deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
   deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

   deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
   deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

   deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
   deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
EOF'
sudo apt-get update
sudo apt-get install -y git zsh
git config --global credential.helper store
# 安装brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# 切换brew源 for bash
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.aliyun.com/homebrew-bottles/api"' >>~/.bash_profile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"' >>~/.bash_profile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git"' >>~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles"' >>~/.bash_profile
source ~/.bash_profile
brew update
# sh
if [ ! -d "$HOME/sh" ]; then
  git clone https://gitee.com/ljstatic/linux-sh.git ~/sh --depth 1
fi
# ohmyzsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
  sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-completions" ]; then
  git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions --depth 1
fi
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then
  git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions --depth 1
fi
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]; then
  git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting --depth 1
fi
if [ ! -d "$HOME/.oh-my-zsh/custom/themes/powerlevel10k" ]; then
  git clone --depth 1 https://github.com/romkatv/powerlevel10k ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
fi
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/fzf-tab" ]; then
  git clone --depth 1 https://github.com/Aloxaf/fzf-tab ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fzf-tab
fi
echo "正在配置zsh"
chsh -s /bin/zsh
cp ./.p10k.zsh ~/.p10k.zsh
cp ./.linjrc ~/.linjrc

sh -c 'cat <<EOF 
export LANG='zh_CN.UTF-8'
export LANGUAGE='en_US:en'
export LC_ALL='en_US.UTF-8'
export TERM=xterm

##### Zsh/Oh-my-Zsh Configuration
export ZSH=\$HOME/.oh-my-zsh

ZSH_THEME="powerlevel10k/powerlevel10k"
plugins=(git vscode yarn zsh-completions zsh-autosuggestions z zsh-syntax-highlighting extract  fzf-tab)

source \$ZSH/oh-my-zsh.sh
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir vcs status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_STATUS_OK=false
POWERLEVEL9K_STATUS_CROSS=true
# To customize prompt, run "p10k configure" or edit ~/.p10k.zsh.
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
[[ ! -f ~/.linjrc ]] || source ~/.linjrc
EOF' >$HOME/.zshrc
# 安装 nvs
cd ~/sh/install && ./init.sh -i nvs
echo "安装完成，请执行 source ~/.zshrc"
